package com.foreverwin.mes.warehouse.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.foreverwin.mes.common.dto.PrintDto;
import com.foreverwin.mes.common.model.PrintLog;
import com.foreverwin.mes.core.base.AjaxResult;
import com.foreverwin.mes.core.base.FrontPage;
import com.foreverwin.mes.warehouse.dto.ReprintDto;
import com.foreverwin.mes.warehouse.model.InventoryReceiveConfirm;
import com.foreverwin.mes.warehouse.service.ReprintService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Ervin Chen
 * @date 2020/3/6 14:32
 */
@RestController
@RequestMapping("/reprint")
public class ReprintController {
    private Logger logger = LoggerFactory.getLogger(ReprintController.class);

    @Autowired
    private ReprintService reprintService;

    @ResponseBody
    @GetMapping("/getPrinterList")
    public AjaxResult getPrinterList() {
        List<PrintLog> result;
        try {
            result = reprintService.getPrinterList();
        } catch (Exception e) {
            logger.error("getPrinterList -=- {}", e.toString());
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(result);
    }

    @ResponseBody
    @GetMapping("/getPrintTemplateList")
    public AjaxResult getPrintTemplateList() {
        List<PrintLog> result;
        try {
            result = reprintService.getPrintTemplateList();
        } catch (Exception e) {
            logger.error("getPrintTemplateList -=- {}", e.toString());
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(result);
    }

    @ResponseBody
    @GetMapping("/getPrintLogList")
    public AjaxResult getPrintLogList(FrontPage<PrintLog> frontPage, ReprintDto reprintDto) {
        Page<PrintLog> result;
        try {
            result = reprintService.getPrintLogList(frontPage, reprintDto);
        } catch (Exception e) {
            logger.error("getPrintLogList -=- {}", e.toString());
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(result);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/_save")
    public AjaxResult reprint(@RequestBody PrintDto printDto) {
        try {
            reprintService.reprint(printDto);
        } catch (Exception e) {
            logger.error("reprint -=- {}", e.toString());
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success();
    }
}
